home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / denext / stripnextsnd.c < prev   
C/C++ Source or Header  |  1991-10-06  |  2KB  |  85 lines

  1. /*
  2.  * Strips the header off NeXT sound files for play on the Sparc
  3.  *
  4.  * Copyright (c) 1990, Keith Edwards
  5.  * May be freely used, modified, distributed, or copied as long as
  6.  * this notice stays intact.
  7.  *
  8.  * Keith Edwards
  9.  * Georgia Tech / SERC / Multimedia Group
  10.  * April 5, 1990
  11.  * <keith@dali.gatech.edu>
  12.  */
  13.  
  14. /*************************************************************************
  15.  stripnextsnd.c:
  16.  If no args, reads from stdin and writes to stdout.  If one arg, opens
  17.  that file and writes to stdout.  If two args, uses arg one as input and
  18.  arg 2 as output.
  19.  *************************************************************************/
  20.  
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <errno.h>
  24. #include <sys/types.h>
  25. #include <sys/uio.h>
  26. #include "next_soundstruct.h"
  27.  
  28. #define BUFSIZE 1024
  29.  
  30. main( argc, argv, envp )
  31.     int argc;
  32.     char *argv[], *envp[];
  33. {
  34.     int in, out;
  35.     unsigned char buf[BUFSIZE];
  36.     SNDSoundStruct sndStruct;
  37.  
  38.         if (argc > 3) {
  39.                 fprintf( stderr, "Usage: %s [infile [outfile]]\n", argv[0] );
  40.                 exit( 1 );
  41.         }
  42.  
  43.     if (argc >= 2) {
  44.             if ((in = open( argv[1], O_RDONLY, NULL )) == -1) {
  45.                        perror( argv[1] );
  46.                        exit( 2 );
  47.           }
  48.         close( 0 );
  49.         dup2( in, 0 );
  50.     }
  51.  
  52.         if (argc == 3) {
  53.                 if ((out = open( argv[2], (O_WRONLY | O_CREAT), NULL )) == -1){
  54.                         perror( argv[2] );
  55.                         exit( 2 );
  56.                 }
  57.                 close( 1 );
  58.                 dup2( out, 1 );
  59.         }
  60.  
  61.     read( 0, (char *) &sndStruct, sizeof( SNDSoundStruct ));
  62.     if (sndStruct.magic != SND_MAGIC) {
  63.         fprintf( stderr, "%s: bad magic number on sound input\n",
  64.                 argv[0] );
  65.         exit( 3 );
  66.     }
  67.     if (sndStruct.dataFormat != SND_FORMAT_MULAW_8) {
  68.         fprintf( stderr, "%s: bad format on sound input (can only read 8-bit mulaw)\n", argv[0] );
  69.         exit( 4 );
  70.     }
  71.     if (sndStruct.samplingRate != (int) SND_RATE_CODEC)
  72.         fprintf( stderr, "%s: warning: sampling rate not CODEC\n",
  73.                 argv[0] );
  74.     if (sndStruct.channelCount != 1)
  75.         fprintf( stderr, "%s: warning: channel count not 1\n",
  76.                 argv[0] );
  77.  
  78.     while (read( 0, buf, BUFSIZE ) == BUFSIZE)
  79.         write( 1, buf, BUFSIZE );
  80.     write( 1, buf, BUFSIZE );
  81.  
  82.     close( in ) ; close( out );
  83.     exit( 0 );
  84. }
  85.